//package com.dc.mqtt.newMqtt;
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.beanutils.ConvertUtils;
//import org.eclipse.paho.client.mqttv3.MqttException;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.Random;
//
//@Configuration
//@Slf4j
//public class MqttConfiguration {
//
//    @Value("${spring.mqtt.serverURIs}")
//    private String host;
//    @Value("${spring.mqtt.username}")
//    private String username;
//    @Value("${spring.mqtt.password}")
//    private String password;
//    @Value("${spring.mqtt.topics}")
//    public String SUB_TOPICS;
//    @Value("${spring.mqtt.qos}")
//    public String qos;
//    private int timeOut = 10;
//    private int keepAlive = 20;
//
//    @Bean//注入spring
//    public MyMQTTClient myMQTTClient() {
//        MyMQTTClient myMQTTClient = new MyMQTTClient(host, username, password, String.valueOf(Math.abs(new Random().nextInt())), timeOut, keepAlive);
//        try {
//            myMQTTClient.connect();
//            int[] convert = (int[]) ConvertUtils.convert(qos.split(","), int.class);
//            MyMQTTClient.getClient().subscribe(SUB_TOPICS.split(","), convert); //重连后订阅需要的主题
//            return myMQTTClient;
//        } catch (MqttException e) {
//            //e.printStackTrace();
//        }
//        return myMQTTClient;
//    }
//
//}
